uniform vec3 camPos;
uniform vec4 camproj1;
uniform vec4 camproj2;
uniform vec4 camproj3;
uniform vec4 camproj4;

varying vec3 Refract;

void main()
{
  //float angle = gl_Vertex[2];
  vec4 newPos;
  newPos[0] = gl_Vertex[0];
  newPos[1] = gl_Vertex[1];
  newPos[2] = gl_Vertex[2];
  newPos[3] = gl_Vertex[3];
  
   vec4 ecPosition  = gl_ModelViewMatrix * gl_Vertex;
   vec3 ecPosition3 = ecPosition.xyz / ecPosition.w;
   mat4 worldMatrix = mat4(camproj1, camproj2, camproj3, camproj4);
   vec4 ecCamPos = worldMatrix * vec4(camPos, 1.0);
   vec3 ecCamPos3 = ecCamPos.xyz / ecCamPos.w;
   
   vec3 i = normalize(ecPosition3 - ecCamPos3);
   vec3 n = normalize(gl_NormalMatrix * gl_Normal);  
   //Refract = refract(i, n, 0.56);
   //Refract = vec3(gl_TextureMatrixInverse[0] * vec4(Refract, 1.0)); //(*)
   
   float falloff = max( dot(i, n), 0.0);
   
   //float falloff_edited = pow((0.5+ 2.0*falloff-1.0 )/2.0 , (0.25+1.5*(abs(falloff*0.637-1))));
   
   float x = 0.1 + (1.0-asin(falloff*1.1));
   float falloff_edited = 1.273*(sin(x) + 0.33 * sin(3.0*x) + 0.2*sin(5.0*x) + 0.14*sin(7.0*x));
   
   gl_FrontColor = falloff_edited;
    //gl_FrontColor =   vec4(1.0, 1.0, 1.0, 1.0) * (-0.5+falloff_edited *0.5);
    //gl_FrontColor =   vec4(1.0, 1.0, 1.0, 1.0) * (1.0 - falloff_edited);
    //gl_FrontColor = dot(vec4(Refract, 1.0),  (vec4(1.0, 0.97, 0.85,1.0)));//, vec4(0.0, 0.0, 0.0, 0.0), Refract);//
    gl_Position = gl_ModelViewProjectionMatrix * newPos;
}















